package com.example.dome1.service.inpl;

import com.example.dome1.dao.UserDao;
import com.example.dome1.service.UserService;
import org.oasisopen.sca.annotation.Scope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;


//<bean id="userService" class="com.example.dome1.service.inpl.UserServiceImpl">
@Service("userService")
//@Scope("prototype")
@Scope("singleton")
public class UserServiceImpl implements UserService {
    //<property name="userDao" ref="userDao"></property>

//    @Autowired  //按照数据类型从Spring容器中进行匹配
//    @Qualifier("userDao")   //是按照id值从容器中进行匹配的，但是此处@Qualifier要结合@Autowired一起使用
    @Resource(name="userDao")   //相当于@Autowired+@Qualifier
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
    public void save(){
        System.out.println(driver);
        userDao.save();
    }

    @Value("${jdbc.driver}")
    public String driver;

    @PostConstruct
    public void init(){
        System.out.println("Service对象的初始化方法");
    }
    @PreDestroy
    public void destroy(){
        System.out.println("Service对象的销毁方法");
    }
}
